package com.ruoyi.jinchuguanli.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.jinchuguanli.domain.Saomachuku;
import com.ruoyi.jinchuguanli.service.ISaomachukuService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * saomachukuController
 *
 * @author ruoyi
 * @date 2023-11-08
 */
@Controller
@RequestMapping("/jinchuguanli/saomachuku")
public class SaomachukuController extends BaseController {
    private final String prefix = "jinchuguanli/saomachuku";

    @Autowired
    private ISaomachukuService saomachukuService;

    @RequiresPermissions("jinchuguanli:saomachuku:view")
    @GetMapping()
    public String saomachuku () {
        return prefix + "/saomachuku";
    }

    /**
     * 查询saomachuku列表
     */
    @RequiresPermissions("jinchuguanli:saomachuku:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list (Saomachuku saomachuku) {
        startPage();
        List<Saomachuku> list = saomachukuService.selectSaomachukuList(saomachuku);
        return getDataTable(list);
    }

    /**
     * 导出saomachuku列表
     */
    @RequiresPermissions("jinchuguanli:saomachuku:export")
    @Log(title = "saomachuku", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export (Saomachuku saomachuku) {
        List<Saomachuku> list = saomachukuService.selectSaomachukuList(saomachuku);
        ExcelUtil<Saomachuku> util = new ExcelUtil<Saomachuku>(Saomachuku.class);
        return util.exportExcel(list, "saomachuku数据");
    }

    /**
     * 新增saomachuku
     */
    @GetMapping("/add")
    public String add () {
        return prefix + "/add";
    }

    /**
     * 新增保存saomachuku
     */
    @RequiresPermissions("jinchuguanli:saomachuku:add")
    @Log(title = "saomachuku", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave (Saomachuku saomachuku) {
        return toAjax(saomachukuService.insertSaomachuku(saomachuku));
    }

    /**
     * 修改saomachuku
     */
    @RequiresPermissions("jinchuguanli:saomachuku:edit")
    @GetMapping("/edit/{id}")
    public String edit (@PathVariable("id") Integer id, ModelMap mmap) {
        Saomachuku saomachuku =
                saomachukuService.selectSaomachukuById(id);
        mmap.put("saomachuku", saomachuku);
        return prefix + "/edit";
    }

    /**
     * 修改保存saomachuku
     */
    @RequiresPermissions("jinchuguanli:saomachuku:edit")
    @Log(title = "saomachuku", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave (Saomachuku saomachuku) {
        return toAjax(saomachukuService.updateSaomachuku(saomachuku));
    }

    /**
     * 删除saomachuku
     */
    @RequiresPermissions("jinchuguanli:saomachuku:remove")
    @Log(title = "saomachuku", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove (String ids) {
        return toAjax(saomachukuService.deleteSaomachukuByIds(ids));
    }
}
